#region Summary

// 
// Owner : JackieHan 
// 
// Solution : UpdateSystem
// 
// Project :Project
// 
// File : PublishImpl.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 实现<see href="IPublish" />
// 
// History : 
//			2011-01-06 17:36:09	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using Jackie.Update.Entities;
using Jackie.Update.Entities.Server;
using Jackie.Update.IBusiness;

#endregion

namespace Jackie.Update.BusinessImpl
{
    /// <summary> 
    /// 实现<see href="IPublish" />
    /// </summary>
    public class PublishImpl : IPublish
    {
        private readonly string serverConfigDirectory;
        private UpdateServerInfo serverConfig;

        public PublishImpl()
        {
            serverConfigDirectory = ConfigurationManager.AppSettings["ServerConfigDirectoryPath"];
            serverConfig = new UpdateServerInfo(serverConfigDirectory);
        }

        public List<UpdateFileInfo> GetNewFiles(string systemName)
        {
            var systemConfig = serverConfig[systemName];
            if (systemConfig == null)
                return new List<UpdateFileInfo>();
            var updateFiles = systemConfig.GetNewFiles();
            return updateFiles;
        }


        public bool CheckSystemVersion(string systemName, string systemVersion)
        {
            var systemConfig = serverConfig[systemName];
            return !systemConfig.PublishLogs.Keys.Contains(systemVersion);
        }


        public void UpdateConfig(string systemName, PublishLogInfo publishLog)
        {
            var systemConfig = serverConfig[systemName];
            systemConfig.SaveToFile(publishLog);
        }


        public string GetPublishDirectory(string systemName)
        {
            var systemConfig = serverConfig[systemName];
            return systemConfig.PublishPath;
        }
    }
}